package com.my.lucky.config;

import com.my.lucky.entity.StockLimitUp;
import com.my.lucky.entity.StockQueryRecord;
import com.my.lucky.entity.SysInfo;
import com.my.lucky.model.Stock;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.*;

@Data
@Configuration
public class IwencaiConfig {
    List<SysInfo> checksysInfos;//策略的数据
    List<Stock> all7Stock;//7天的数据
    List<StockLimitUp> limitstocks10d;//10天涨停的
    List<StockQueryRecord> now10Drecords = new ArrayList<>();
    List<StockQueryRecord> nowTodayDrecords = new ArrayList<>();
    Map<String, Integer> sunstocks = new HashMap<>(); //概念有的个股数量
    /**
     * gainian:
     * url: http://k872y46596.zicp.fun:31030/api/wencai?question=
     * keyword: 所属概念日线KDJ向上,所属概念日线KDJ的J线高于K线
     * interval: 300
     * search:
     * url: http://k872y46596.zicp.fun:31030/api/wencaizhishu?question=
     * keyword: 概念主力增仓上涨,{日}的日线KDJ的J线在K线之上,{日}的周线KDJ向上,{时}的60分钟周期分时KDJ向上,{分}的30分钟周期分时KDJ向上,
     * interval: 300
     * hot:
     * url: http://k872y46596.zicp.fun:31030/api/wencai?question=
     * keyword: 热度排行榜,
     * interval: 16
     * baseData:
     * url: http://k872y46596.zicp.fun:31030/api/wencai?question=
     * interval: 16
     * focus: 300820,300429,301196
     */
    @Value("${iwencai.local:false}")
    private Boolean isLocal;
    @Value("${iwencai.gainian.keyword}")
    private String gainianKeyword;
    @Value("${iwencai.gainian.interval}")
    private Long gainianInterval;
    @Value("${iwencai.gainian.url}")
    private String searchGainianUrl;
    @Value("${iwencai.search.keyword}")
    private String searchKeyword;
    @Value("${iwencai.search.interval}")
    private Long searchInterval;
    @Value("${iwencai.search.url}")
    private String searchUrl;
    @Value("${iwencai.focus}")
    private String focus;
    private String focusBoll;//关注的股票boll扩张
    private String allOptional;
    private String focusGaiNian;
    @Value("${iwencai.basedata.url}")
    private String baseDataUrl;
    @Value("${iwencai.basedata.interval}")
    private String baseDataInterval;
    @Value("${iwencai.hot.url}")
    private String hotUrl;
    @Value("${iwencai.hot.keyword}")
    private String hotKeyword;
    @Value("${iwencai.hot.interval}")
    private String hotInterval;
    @Value("${iwencai.baseUrl}")
    private String baseUrl;
    private Random random = new Random();

    public String getUrl() {
        if (baseUrl == null || baseUrl.trim().isEmpty()) {
            return null;
        }

        // 按逗号分割baseUrl
        String[] urls = baseUrl.split(",");

        // 去除空白字符
        for (int i = 0; i < urls.length; i++) {
            urls[i] = urls[i].trim();
        }

        // 随机选择一个URL
        if (urls.length > 0) {
            int index = random.nextInt(urls.length);
            return urls[index];
        }

        return null;
    }

}
